package com.teaphy.readlist;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartHttpServletRequest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

/**
 * @author teaphy
 * @desc
 * @since 20:34
 */

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ReadlistApplication.class)
@AutoConfigureMockMvc
public class MocMvcTestDemo {

    @Autowired
    private MockMvc mockMvc;

    @Test
    public void testMoc() {
        try {
            MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/testMoc"))
                    .andExpect(MockMvcResultMatchers.status().isOk())
                    .andReturn();
            int status = mvcResult.getResponse().getStatus();
            String content = mvcResult.getResponse().getContentAsString();
            System.out.println("status: " + status);
            System.out.println("content: " + content);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
